#region Summary

// 
// Owner : JackieHan 
// 
// Solution : LearnSolution 
// 
// Project : JackieHan.NHiberante.SessionManage
// 
// File : ThreadSessionStorage.cs
// 
// CopyRight : Copyright © 2010-2011 Skomart Corporation, All Rights Reserved 
// 
// Summary : Thread Session
// 
// History : 
//			2010-09-28 12:02:26	    Create 
// 

#endregion

#region Using

using System;
using NHibernate;

#endregion

namespace JackieHan.NHiberante.SessionManage
{
    /// <summary> 
    /// Thread Session 
    /// </summary>
    public class ThreadSessionStorage : ISessionStorage
    {
        [ThreadStatic]
        private static ISession threadSession;

        #region ISessionStorage Members

        public ISession Get()
        {
            if ((threadSession != null) && (!threadSession.IsConnected))
            {
                threadSession.Reconnect();
            }
            return threadSession;
        }

        public void Set(ISession value)
        {
            if (value.IsConnected)
                value.Disconnect();
            threadSession = value;
        }

        #endregion
    }
}